<template>
  <div class="common-seach-wrap">
    <div>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="拼团列表" name="active"></el-tab-pane>
        <el-tab-pane label="拼团审核" name="audit">
        </el-tab-pane>
        <el-tab-pane label="拼团设置" name="setting">
        </el-tab-pane>
      </el-tabs>
    </div>
    <!--拼团活动-->
    <Active v-if="activeName == 'active'"></Active>
    <!--基础设置-->
    <getSetting v-if="activeName == 'setting'"></getSetting>
	<!--审核记录-->
    <Audit v-if="activeName == 'audit'"></Audit>
  </div>
</template>
<script>
import bus from '@/utils/eventBus.js';
import PlusApi from '@/api/plus.js';
import Active from './active/index';
import getSetting from './setting/index';
import Audit from "./audit/index"

export default {
  components: {
    Active,
    getSetting,
    Audit
  },
  data() {
    return {
      formInline: {
        nick_name: ''
      },
      /*参数*/
      param: {},
      /*当前选中*/
      activeName: 'active',
      /*切换数组*/
      sourceList: [
        {
          key: 'active',
          value: '拼团活动',
          path:'/plus/assemble/active/index'
        },
        {
          key: 'setting',
          value: '基础设置',
          path:'/plus/assemble/setting/index'
        },
        {
          key: 'audit',
          value: '审核记录',
          path:'/plus/assemble/audit/index'
        },
      ],
      /*权限筛选后的数据*/
      tabList:[],
      /*判断third是否有参数*/
      is_third_param: false
    };
  },
  watch:{

    //监听路由
    $route(to, from) {
      this.init();
    }
  },
  created() {

    this.init();

  },
  beforeDestroy() {
    //发送类别切换
    bus.$emit('tabData', { active: null, tab_type:'assemble',list: [] });
    bus.$off('activeValue');
  },
  methods: {

    /*初始化方法*/
    init(){
      this.tabList=this.authFilter();

      if(this.tabList.length>0){
        this.activeName=this.tabList[0].key;
      }

      if (this.$route.query.type != null) {
        this.activeName = this.$route.query.type;
      }

      /*监听传插件的值*/
      bus.$on('activeValue', res => {
        if (this.is_third_param) {
          this.param.user_id = '';
          this.is_third_param = false;
        }
        this.activeName = res;
      });

      //发送类别切换
      let params = {
        active: this.activeName,
        list: this.tabList,
        tab_type:'assemble'
      };
      bus.$emit('tabData', params);
    },

    /*权限过滤*/
    authFilter(){
      let list=[];
      for(let i=0;i<this.sourceList.length;i++){
        let item=this.sourceList[i];
        if(this.$filter.isAuth(item.path)){
          list.push(item);
        }
      }
      return list;
    },
    handleClick(e){
      
    }

  }
};
</script>
